package com.service.single.util;

import lombok.Data;

@Data
public class R<T> {

    private int code = 0;
    private String msg;
    private long count = 0;
    private T data;


    public static <T> R<T> faild() {
        R<T> ret = new R<T>();
        ret.setCode(-1);
        ret.setMsg("fail");
        return ret;
    }

    public static <T> R<T> faild(T data) {
        R<T> ret = R.faild();
        ret.setData(data);
        return ret;
    }

    public static <T> R<T> faild(String msg, int code) {
        R fail = faild(msg);
        fail.setCode(code);
        return fail;
    }

    public static <T> R<T> faild(String msg, int code, T data) {
        R fail = faild(msg);
        fail.setCode(code);
        fail.setData(data);
        return fail;
    }

    public static <T> R<T> faild(String msg) {
        R<T> ret = R.faild();
        ret.setMsg(msg);
        return ret;
    }

    public static <T> R<T> success(String msg) {
        R<T> ret = R.success();
        ret.setMsg(msg);
        return ret;
    }


    public static <T> R<T> success() {
        R<T> ret = new R<T>();
        ret.setMsg("success");
        ret.setCode(200);
        return ret;
    }


    public static <T> R<T> success(T data) {
        R<T> ret = R.success();
        ret.setData(data);
        return ret;
    }

    public static <T> R<T> success(long count, T data) {
        R<T> ret = R.success();
        ret.setCount(count);
        ret.setData(data);
        return ret;
    }

}
